package com.rd.student.wulian.wanggaobo.day0728.practice02;

public class SwitchName {
//    public static void main(String[] args) throws Exception{
//
//
//    Scanner sc = new Scanner(System.in);
//    String name = sc.next();
//    int index =name.indexOf(" ");
//    if(index!=-1){
//        String firstname = name.substring(0, index);
//        String lastname = name.substring(index+1);
//        String newname = lastname + " " + firstname;
//
//    }
//    else {
//        System.out.println("请输入一个中间包含空格的有效名字");
//    }
//    }
    public static String swapname(String fullName) {
        int spaceIndex = fullName.indexOf(" ");


        if (spaceIndex != -1) {
            String firstname = fullName.substring(0, spaceIndex);
            String lastname = fullName.substring(spaceIndex + 1);


            String newname = lastname + " " + firstname;
            return newname;
        } else {
            return "请输入一个中间包含空格的有效名字";
        }
    }

    public static void main(String[] args) {
        swapname("w gb");
    }
}

